//
//  VC3CollectionViewSecond.swift
//  ChapterAll
//
//  Created by Kevin on 2020/4/23.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VC3CollectionViewSecond: UIViewController {
    
    private let collectionID = "VC3CollectionViewSecond_ID"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let layout = View3CollectionLayout()
        layout.itemSize = CGSize(width: 100, height: 100)
        layout.minimumLineSpacing = 30
        layout.minimumInteritemSpacing = 30
        
        let collectionView = UICollectionView(frame: view.frame, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.white
        collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: collectionID)
        view.addSubview(collectionView)
    }
    
    func getColor() -> CGFloat {
        return CGFloat(arc4random() % 255) / 255.0
    }
}

extension VC3CollectionViewSecond: UICollectionViewDelegate,UICollectionViewDataSource {
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: collectionID, for: indexPath)
        cell.layer.cornerRadius = 25
        cell.layer.masksToBounds = true
        cell.backgroundColor = UIColor.init(displayP3Red: getColor(), green: getColor(), blue: getColor(), alpha: 1)
        return cell
    }
}
